Overview of Indexes and Queries

Description

Two of the ways that Alpha Anywhere creates an ordered list of selected records is by using indexes and queries. Keys and key expressions are the basis for indexes and queries.

Index

  • What is an index?

    Alpha Anywhere uses indexes to determine the order in which records appear in a table, and to quickly find records. An index is a table that contains keys representing every record in the table. The keys are stored in order. By looking up a key in the index, Alpha Anywhere can quickly find the corresponding record in the table. An index key can be a single field, or you can create the key from several fields. For example, to order the records in a table by State, and within State, ordered by City, you create an index on State+City.

  • How do you create an index?

    Every index has a key expression, which indicates the sort order for the index. The key expression can be a combination of one or more fields, and other elements, such as operators, functions, and text strings. To help you define the index key expression, you use the Index Builder. Alpha Anywhere builds the index after you define it. Alpha Anywhere maintains and updates the index, adjusting its ordered list of selected records, when you add, change, or delete records. Indexes can have filters and other options.

  • When do you use an index?

    You use an index when you want to quickly find a record or test for its existence.

  • Are there any drawbacks to using an index?

    The potential problem associated with using an index is that, under certain error conditions, they can get out of date. as a result, your application should include provision for regular index updates.

Query

  • What is a query?

    A query is an ad-hoc or temporary index that you generate for short term needs. A query produces an ordered list of selected records, called a query list. You can save the query definition for reuse.

  • How do you create a query?

    You define a query by entering field names and expressions in the Query Genie, or by using the Query by Expression ( Query > Query By Expression... ), Query by Form ( Query > Query By Form... ), or Special Queries ( Query > Special Queries... ) dialogs.

  • When do you use a query?

    You use a query when your retrieval (and indexing) requirements are unpredictable or are frequently changing.

  • Are there any drawbacks to using a query?

    If the record data changes, you must re-run the query to update the query list.

Alpha Anywhere maintains indexes in sorted order and updates the index any time you add or change a record. By creating an index, you speed up queries and other Operations that use the indexed fields. Indexed fields are fields that are commonly used to find data in a table. However, creating indexes on every field is likely to slow down data entry, as Alpha Anywhere updates each index whenever you enter or change a record. Query lists and indexes are similar, in that they both contain a sorted list of key values. However, Alpha Anywhere updates indexes when you add or change records; query lists are static, and become out of date when you add and change records. To update a query list, you must refresh the current query, or generate a new query list by re-running the query.

See Also